package com.huel.liweijian.Service;

import com.huel.liweijian.Service.Operations.*;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Liweijian.
 * @date 2024/9/4 10:42
 */
@Component
public class CalculatorFactory {
    private static final Map<String, CalculatorService> operations = new HashMap<>();

    static {
        operations.put("add", new AddOperation());
        operations.put("subtract", new SubOperation());
        operations.put("multiply", new MultiplyOperation());
        operations.put("divide", new DivideOperation());
        operations.put("modulo", new ModuloOperation());
        operations.put("sqrt", new SqrtOperation());
    }

    public CalculatorService getOperation(String operation) {
        return operations.get(operation.toLowerCase());
    }
}
